package com.ly.lw.styledo.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.ly.lw.styledo.R;
import com.ly.lw.styledo.fragment.BrandFragment;
import com.ly.lw.styledo.fragment.CategoryFragmentHome;
import com.ly.lw.styledo.fragment.MainFragment;
import com.ly.lw.styledo.fragment.MyFragment;
import com.ly.lw.styledo.utils.FragmentTableUtils;

import java.util.ArrayList;


public class MainActivity extends FragmentActivity{
    @ViewInject(R.id.rgs)
    private RadioGroup rgs;
    ArrayList<Fragment>  fragments = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        ViewUtils.inject(this);
        fragments.add(new MainFragment());
        fragments.add(new CategoryFragmentHome());
        fragments.add(new BrandFragment());
        fragments.add(new MyFragment());
        //测试测试 
        new FragmentTableUtils(getSupportFragmentManager(),fragments,R.id.main_fragment,rgs);
    }

    private long firstTime;

    @Override
    public void onBackPressed() {
        long secondTime = System.currentTimeMillis();
        if (secondTime - firstTime > 2000) {
            Toast.makeText(this, "再点击一次将退出应用程序", Toast.LENGTH_SHORT).show();
            firstTime = secondTime;//更新firstTime
            return;
        } else {
            //两次按键小于2秒时，退出应用
            android.os.Process.killProcess(android.os.Process.myPid());
        }
    }


}
